define(function(require){
    $(function(){
    	/*------------------------------ 媒体资源 ,流量采购管理者------------------------------*/

        /* 表格 */
        var bodyTemplate =
            '<tr>'
        	+ '<td class="txtc">{position_name}</td>'
        	+ '<td class="txtc">{position_size}</td>'
            + '<td class="txtc">{media_name}</td>'
            + '<td class="txtc">{circle}</td>'
            + '<td class="txtc">{bid_type}</td>'
            + '<td class="txtc">{bid_price}</td>'
            + '<td class="txtc">{pv}</td>'
            + '<td class="txtc">{click}</td>'
            + '<td class="txtc">{shared}</td>'
            + '<td class="txtc">{floor}</td>'
            + '<td class="txtc"><a class="ibtn showChart" href="javascript:;">查看报表</a></td>'
            + '</tr>';
        
        var pageTemplate =
            '<div class="gridTotal">共<b>{totalCount}</b>个广告活动</div>' +
            '<input type="button" value="首页" class="page-bt first-page" title="首页">' +
            '<input type="button" value="上一页" class="page-bt pre-page" title="上一页">' +
            '第{pageNo}页' +
            '<input type="button" value="下一页" class="page-bt next-page" title="下一页">' +
            '<input type="button" value="末页" class="page-bt last-page" title="末页">' +
            '共{totalPage}页&nbsp;&nbsp;跳转至' +
            '<input type="text" size="4" maxlength="5" class="some-page"/>' +
            '每页<select class="page-size"><option value="10">10</option><option value="20">20</option></select>条记录';
        
        var date = $('[name=reservation]').val().split(' 至 ');
	    var grid = Grid.init({
	            holder:'mediaResources',
	            bodyTemplate:bodyTemplate,
	            dataSource:'/trp/traffic_list/',
	            pageTemplate:pageTemplate
	        });
        grid.send({
    		search_text: '',
    		start: date[0],		//必填
    		end: date[1],		//必填
    		orderBy: '',
    		pageSize: 20,
    		pageNo: 1
    	});
        
        /* 数据筛选 */
        var filterData = function(){
        	var txt = $('.searchbox-ipt').val(),
            	date = $('[name=reservation]').val().split(' 至 ');
            grid.send({
        		search_text: txt,
        		start: date[0],
        		end: date[1],
        		orderBy: '',
        		pageSize: 20,
        		pageNo: 1
        	});
        };
        
        /* 日期选择 */
        $('input[name=reservation]').daterangepicker({
            format:'YYYY-MM-DD'
        }, function(start, end, label) {
        	console.log(start.toISOString(), end.toISOString(), label);
        	filterData();
        });
        
        /* 搜索 */
        $('.searchbox-btn').click(filterData);
        
    });
});